package com.example.controller;

import com.example.dto.ResultDTO;
import com.example.model.User;
import com.example.service.impl.SubscribeService;
import com.example.utils.authUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author by admin, Email xx@xx.com, Date on 2020/5/28.
 * PS: Not easy to write code, please indicate.
 */
@RestController
public class SubscribeController {
    @Autowired
    private SubscribeService subscribeService;

    //获取关注列表
    @GetMapping("/getlikelist")
    public ResultDTO getLikeList(){
        User user = authUtils.getuser();
        if (user!=null){
            List<User> authorList=subscribeService.getLikeListById(user.getId().intValue());
            if (!authorList.isEmpty()){
                return ResultDTO.okOf("查询成功！！！",authorList);
            }
        }
        return ResultDTO.okOf("查询成功！！！");
    }
    //获取订阅用户列表
    @GetMapping("/getSubscribelist")
    public ResultDTO getSubscribeList(){
        User user = authUtils.getuser();
        if (user!=null){
            List<User> authorList=subscribeService.getSubscribeListById(user.getId().intValue());
            if (!authorList.isEmpty()){
                return ResultDTO.okOf("查询成功！！！",authorList);
            }
        }
        return ResultDTO.okOf("查询成功！！！");
    }
    //删除关注用户
    @DeleteMapping("/dellikeuser{userid}")
    public ResultDTO dellikeId(@PathVariable Integer userId){
        subscribeService.deluser(userId);
        return ResultDTO.okOf("删除成功！！！");
    }


}
